<?php 

// Coding by XAD of Nightfall
// Copyright by SpheraIT
// GPL Source

if (extension_loaded('gettext')) {
	if (isset($_COOKIE['lang'])) {
		setlocale(LC_MESSAGES,  $_COOKIE['lang']);
//    setcookie("lang",  $_COOKIE['lang'], time()+2592000);
  } else {
			setlocale(LC_MESSAGES,  'en_US');
	}
	bindtextdomain('main','../../i18n');
  textdomain('main');
}

$wScript = 'sudo /var/www/html/private/smtpconfig/retrieve_smtpconfig.pl';
$wScriptDoddo = 'sudo /var/www/html/private/smtpconfig/smtpconfig.sh';

require_once('db_connect.php');

$action = $_REQUEST['action'];


if ($action == 'savesmtp') {
	
		$masquarade = $_POST["masquarade"];
		$smtphost = $_POST["smtphost"];
		$smtppassword = $_POST["smtppassword"];
		$smtplogin = $_POST["smtplogin"];
		$fromemail = $_POST["fromemail"];
		
		$sql = "UPDATE smtpconfig SET smtplogin='$smtplogin',smtppassword='$smtppassword',smtphost='$smtphost',masquarade='$masquarade',fromemail='$fromemail'";

		$res =& $db->query($sql);
		if (DB::isError($res)) {
		    die($res->getMessage());
		}

	unset($smtplogin);
	unset($smtppassword);
	unset($smtphost);
	unset($masquarade);
    unset($fromemail);
	
	exec($wScript);
	exec($wScriptDoddo);
	
}

$sql = "SELECT * FROM smtpconfig";
$results = $db->getAll($sql);
if(DB::IsError($results)) {
	die($results->getMessage());
}


foreach ($results as $result) {

	$fromemail = $result[4];
	$masquarade = $result[3];
	$smtphost = $result[2];
	$smtppassword = $result[1];
	$smtplogin = $result[0];

}

?>

<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<link href="mainstyle.css" rel="stylesheet" type="text/css">
<title>SMTP WebEditor</title>
</HEAD>

<BODY text="#000000" vLink="#000000" aLink="#000000" link="#000000" bgColor="#eeeeee" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<form name="general" action="smtpconfig.php" method="post">
<input type="hidden" name="action" value="savesmtp"/>

<table width="100%" border="0" cellspacing="3" cellpadding="0">
   <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
	<tr>
    <td width="45%"><b><?php echo _("SMTP Login")?>:</b></td>
    <td width="55%"><input name="smtplogin" type="text" id="smtplogin" value="<?php echo $smtplogin?>" size="35" maxlength="50"></td>
	</tr>
	<tr>
    <td width="45%"><b><?php echo _("SMTP Password")?>:</b></td>
    <td width="55%"><input name="smtppassword" type="password" id="smtppassword" value="<?php echo $smtppassword?>" size="35" maxlength="50"></td>
	</tr>
	<tr>
    <td width="45%"><b><?php echo _("SMTP Hostname")?>:</b></td>
    <td width="55%"><input name="smtphost" type="text" id="smtphost" value="<?php echo $smtphost?>" size="35" maxlength="50"></td>
	</tr>
	<tr>
    <td width="45%"><b><?php echo _("Domain Masquarade")?>:</b></td>
    <td width="55%"><input name="masquarade" type="text" id="masquarade" value="<?php echo $masquarade?>" size="35" maxlength="50"></td>
	</tr>
	<tr>
    <td width="45%"><b><?php echo _("Mail From")?>:</b></td>
    <td width="55%"><input name="fromemail" type="text" id="fromemail" value="<?php echo $fromemail?>" size="35" maxlength="50"></td>
	</tr>
	<tr>
	<td colspan="2"><div align="right"><input name="Submit" type="submit" value="Salva"></div></td>
	<tr>
	<td colspan="2">* <?php echo _("Read the documentation before configuring this service.")?></td>
	</tr>
	</tr>

  </table>
</form>
</BODY></HTML>